package com.simons.common.ftp.simple;

import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

import com.simons.common.ftp.BaseFTPOper;

public class SimpleFTPOper extends BaseFTPOper{
	private ConnectParam connectParam;

	public SimpleFTPOper(ConnectParam connectParam) {
		this.connectParam = connectParam;
	}

	public boolean connect() throws SocketException, IOException {
		if (connectParam == null) {
			return false;
		}

		this.ftpClient = new FTPClient();
		this.ftpClient.connect(connectParam.getHost(), connectParam.getPort());
		this.ftpClient.login(connectParam.getUsername(), connectParam.getPassword());

		int reply = this.ftpClient.getReplyCode();

		return FTPReply.isPositiveCompletion(reply);
	}

	public void closeConnect() throws IOException {
		try {
			ftpClient.logout();
		} finally {
			this.ftpClient.disconnect();
		}
	}

	
}
